import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
export const constantRoutes  = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    name: '订单管理列表',
    children: [{
      path: 'dashboard',
      name: '订单管理',
      component: () => import('@/views/OrderManger/index'),
      meta: { title: '订单管理', icon: 'dashboard' }
    },
    {
      path: 'OrderManger/edit',
      name: '编辑订单',
      hidden: true,
      component: () => import('@/views/OrderManger/edit'),
      meta: { title: '编辑订单', icon: 'form' }
    }]
  }
]

export const asyncRoutes  = [
  {
    path: '/dispatch',
    component: Layout,
    name: '派车单管理列表',
    children: [
      {
        path: 'index',
        name: '派车单管理',
        component: () => import('@/views/DispatchManagement/index'),
        meta: { title: '派车单管理', icon: 'form' }
      },
      {
        path: 'add',
        name: '新建派车单',
        hidden: true,
        component: () => import('@/views/DispatchManagement/add'),
        meta: { title: '新建派车单', icon: 'form' }
      }
    ]
  },
  { path: '*', redirect: '/pages/404', hidden: true },

];
const createRouter = () => new Router({
  mode: 'hash',
  linkActiveClass: 'open active',
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
